//
//  ZTHiperTimer.m
//  ZHYYTool
//
//  Created by MT-SW-005 on 2021/9/17.
//  Copyright © 2021 MT-SW-005. All rights reserved.
//

#import "ZTHiperTimer.h"

@implementation ZTHiperTimer

-(id) init
{
    return (self = [super init]);
}


-(int) durationMillisecond
{
    if(gettimeofday(&tv, NULL) == 0)
        mEnd = tv.tv_sec * 1000 + tv.tv_usec/1000;
    return (int)mEnd - (int)mStart;
}


+(void) DelaySecond:(double) delaytime
{
    [self DelayMillsecond: delaytime * 1000];
}


+(void) DelayMillsecond:(int) delaytime
{
    ZTHiperTimer* timer = [[ZTHiperTimer alloc] init];
    [timer Start];
    while (true)
    {
        if([timer durationMillisecond] >= delaytime)
        {
            break;
        }
    }
}


-(void) Start
{
    //time(&mStart);
    if(gettimeofday(&tv, NULL) == 0)
        mStart = tv.tv_sec * 1000 + tv.tv_usec/1000;
}
@end
